package com.itcam.interview.pro00.disignmodel.strategy;

// 4. 使用上下文类动态切换策略
public class StrategyPatternExample {
    public static void main(String[] args) {
        // 初始使用无折扣策略
        ShoppingCart cart = new ShoppingCart(new NoDiscountStrategy());
        double originalPrice = 100.0;

        // 计算无折扣的总价
        double totalWithNoDiscount = cart.calculateTotal(originalPrice);
        System.out.println("无折扣总价: " + totalWithNoDiscount);

        // 切换到 10% 折扣策略
        cart.setDiscountStrategy(new TenPercentDiscountStrategy());
        double totalWithTenPercentDiscount = cart.calculateTotal(originalPrice);
        System.out.println("10% 折扣后总价: " + totalWithTenPercentDiscount);

        // 切换到 20% 折扣策略
        cart.setDiscountStrategy(new TwentyPercentDiscountStrategy());
        double totalWithTwentyPercentDiscount = cart.calculateTotal(originalPrice);
        System.out.println("20% 折扣后总价: " + totalWithTwentyPercentDiscount);
    }
}